package com.android.djlmapp.adapter.kaika;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.djlmapp.R;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 拍照
 * 2017/8/8
 * 张鹏
 */
public class MyPhotoAdapter extends BaseAdapter {
    private Context ctx;
    private ArrayList<String> list;
    private HashMap<String, String> bitmapList;

    public MyPhotoAdapter(Context ctx, ArrayList<String> list, HashMap<String, String> bitmapList) {
        this.ctx = ctx;
        this.list = list;
        this.bitmapList = bitmapList;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public String getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = View.inflate(ctx, R.layout.list_shangchuan_item, null);

        ImageView shangchuan_iv_img = (ImageView) view.findViewById(R.id.shangchuan_iv_img);
        TextView tv_name = (TextView) view.findViewById(R.id.tv_name);
        tv_name.setText(list.get(position));

        String str = bitmapList.get(position + "");
        if (str != null && !TextUtils.isEmpty(str)) {
            Glide.with(ctx).load(str).into(shangchuan_iv_img);
        } else {
            Glide.with(ctx).load(R.drawable.add).into(shangchuan_iv_img);
        }
        return view;
    }

    public void update(ArrayList<String> list, HashMap<String, String> bitmapList) {
        this.list = list;
        this.bitmapList = bitmapList;
        notifyDataSetChanged();
    }
}